# -*- coding: utf-8 -*-
"""
Created on Sat Dec 12 19:39:04 2015

@author: liangrongli
"""

from scrapy import Spider
from scrapy.selector import Selector

from stack.items import StackItem

class StackSpider(Spider):
    name = "stack"
    allowed_domains = ["python.jobbole.com/"]
    start_urls = ["http://python.jobbole.com/all-posts/"]

    def parse(self,response):
        questions = Selector(response).xpath('//div[@class="post-meta"]/p[1]')
        for question in questions:
            item = StackItem()
            item['title'] = question.xpath('a[@class="archive-title"]/text()').extract()[0]
            item['url'] = question.xpath('a[@class="archive-title"]/@href').extract()[0]
            # item['title'] = question.xpath('//div[@id="archive"]//p[1]/a[1]/text()').extract()[0]
            # item['url'] = question.xpath('//div[@id="archive"]//p[1]/a[1]/@href').extract()[0]
            yield item
